<!--
 * @Author: Freude Xu
 * @Date: 2021-10-08 11:20:59
 * @LastEditors: Freude Xu
 * @LastEditTime: 2021-10-08 11:40:16
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            height: 0;
            padding: 25% 0;
            background-color: blueviolet;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
        }
    </style>
</head>

<body>
    <!-- 将盒子设为水平垂直居中，并且让高永远等于宽的一半 -->
    <div></div>
</body>

</html>